﻿// Decompiled with JetBrains decompiler
// Type: Bannerlord.ModuleManager.ModuleInfoExtendedExtensions
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using System;
using System.Collections.Generic;
using System.Linq;

#nullable enable
namespace Bannerlord.ModuleManager
{
  internal static class ModuleInfoExtendedExtensions
  {
    public static IEnumerable<DependentModuleMetadata> DependenciesAllDistinct(
      this ModuleInfoExtended module)
    {
      return module.DependenciesAll().DistinctBy<DependentModuleMetadata, string>((Func<DependentModuleMetadata, string>) (x => x.Id));
    }

    public static IEnumerable<DependentModuleMetadata> DependenciesAll(
      this ModuleInfoExtended module)
    {
      foreach (DependentModuleMetadata metadata in (IEnumerable<DependentModuleMetadata>) module.DependentModuleMetadatas)
        yield return metadata;
      foreach (DependentModule metadata in (IEnumerable<DependentModule>) module.DependentModules)
        yield return new DependentModuleMetadata()
        {
          Id = metadata.Id,
          LoadType = LoadType.LoadBeforeThis,
          IsOptional = metadata.IsOptional,
          Version = metadata.Version
        };
      foreach (DependentModule metadata in (IEnumerable<DependentModule>) module.ModulesToLoadAfterThis)
        yield return new DependentModuleMetadata()
        {
          Id = metadata.Id,
          LoadType = LoadType.LoadAfterThis,
          IsOptional = metadata.IsOptional,
          Version = metadata.Version
        };
      foreach (DependentModule metadata in (IEnumerable<DependentModule>) module.IncompatibleModules)
        yield return new DependentModuleMetadata()
        {
          Id = metadata.Id,
          IsIncompatible = true,
          IsOptional = metadata.IsOptional,
          Version = metadata.Version
        };
    }

    public static IEnumerable<DependentModuleMetadata> DependenciesToLoadDistinct(
      this ModuleInfoExtended module)
    {
      return module.DependenciesToLoad().DistinctBy<DependentModuleMetadata, string>((Func<DependentModuleMetadata, string>) (x => x.Id));
    }

    public static IEnumerable<DependentModuleMetadata> DependenciesToLoad(
      this ModuleInfoExtended module)
    {
      foreach (DependentModuleMetadata metadata in module.DependentModuleMetadatas.Where<DependentModuleMetadata>((Func<DependentModuleMetadata, bool>) (x => !x.IsIncompatible)))
        yield return metadata;
      foreach (DependentModule metadata in (IEnumerable<DependentModule>) module.DependentModules)
        yield return new DependentModuleMetadata()
        {
          Id = metadata.Id,
          LoadType = LoadType.LoadBeforeThis,
          IsOptional = metadata.IsOptional,
          Version = metadata.Version
        };
      foreach (DependentModule metadata in (IEnumerable<DependentModule>) module.ModulesToLoadAfterThis)
        yield return new DependentModuleMetadata()
        {
          Id = metadata.Id,
          LoadType = LoadType.LoadAfterThis,
          IsOptional = metadata.IsOptional,
          Version = metadata.Version
        };
    }

    public static IEnumerable<DependentModuleMetadata> DependenciesLoadBeforeThisDistinct(
      this ModuleInfoExtended module)
    {
      return module.DependenciesLoadBeforeThis().DistinctBy<DependentModuleMetadata, string>((Func<DependentModuleMetadata, string>) (x => x.Id));
    }

    public static IEnumerable<DependentModuleMetadata> DependenciesLoadBeforeThis(
      this ModuleInfoExtended module)
    {
      foreach (DependentModuleMetadata metadata in module.DependentModuleMetadatas.Where<DependentModuleMetadata>((Func<DependentModuleMetadata, bool>) (x => x.LoadType == LoadType.LoadBeforeThis)))
        yield return metadata;
      foreach (DependentModule metadata in (IEnumerable<DependentModule>) module.DependentModules)
        yield return new DependentModuleMetadata()
        {
          Id = metadata.Id,
          LoadType = LoadType.LoadBeforeThis,
          IsOptional = metadata.IsOptional,
          Version = metadata.Version
        };
    }

    public static IEnumerable<DependentModuleMetadata> DependenciesLoadAfterThisDistinct(
      this ModuleInfoExtended module)
    {
      return module.DependenciesLoadAfterThis().DistinctBy<DependentModuleMetadata, string>((Func<DependentModuleMetadata, string>) (x => x.Id));
    }

    public static IEnumerable<DependentModuleMetadata> DependenciesLoadAfterThis(
      this ModuleInfoExtended module)
    {
      foreach (DependentModuleMetadata metadata in module.DependentModuleMetadatas.Where<DependentModuleMetadata>((Func<DependentModuleMetadata, bool>) (x => x.LoadType == LoadType.LoadAfterThis)))
        yield return metadata;
      foreach (DependentModule metadata in (IEnumerable<DependentModule>) module.ModulesToLoadAfterThis)
        yield return new DependentModuleMetadata()
        {
          Id = metadata.Id,
          LoadType = LoadType.LoadAfterThis,
          IsOptional = metadata.IsOptional,
          Version = metadata.Version
        };
    }

    public static IEnumerable<DependentModuleMetadata> DependenciesIncompatiblesDistinct(
      this ModuleInfoExtended module)
    {
      return module.DependenciesIncompatibles().DistinctBy<DependentModuleMetadata, string>((Func<DependentModuleMetadata, string>) (x => x.Id));
    }

    public static IEnumerable<DependentModuleMetadata> DependenciesIncompatibles(
      this ModuleInfoExtended module)
    {
      foreach (DependentModuleMetadata metadata in module.DependentModuleMetadatas.Where<DependentModuleMetadata>((Func<DependentModuleMetadata, bool>) (x => x.IsIncompatible)))
        yield return metadata;
      foreach (DependentModule metadata in (IEnumerable<DependentModule>) module.IncompatibleModules)
        yield return new DependentModuleMetadata()
        {
          Id = metadata.Id,
          IsIncompatible = true,
          IsOptional = metadata.IsOptional,
          Version = metadata.Version
        };
    }
  }
}
